<!DOCTYPE html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Actor-class registration &#8212; Pytch  documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=03e43079" />
    <link rel="stylesheet" type="text/css" href="../../_static/classic.css?v=36340f97" />
    <link rel="stylesheet" type="text/css" href="../../_static/css/pytch-classic.css?v=0321735e" />
    
    <script src="../../_static/documentation_options.js?v=7f41d439"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="icon" href="../../_static/favicon.ico"/>
    <link rel="author" title="About these documents" href="../../about.html" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Threading model" href="threading-model.html" />
    <link rel="prev" title="Actor: Sprite and Stage" href="actor.html" /> 
  </head><body>
<div class="NavBar">
  <a href="../../../app/"><h1>Pytch</h1></a>
  <ul>
    <a href="https://pytch.scss.tcd.ie/"><li>About Pytch</li></a>
    <a href="../../index.html"><li>Help</li></a>
    <a href="../../../app/tutorials/"><li>Tutorials</li></a>
    <a href="../../../app/my-projects/"><li>My projects</li></a>
  </ul>
</div>
<div class="warning-work-in-progress">
  <p>These help pages are incomplete — we are working on it!</p>
</div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="actor-class-registration">
<h1>Actor-class registration<a class="headerlink" href="#actor-class-registration" title="Link to this heading">¶</a></h1>
<p>Each <code class="docutils literal notranslate"><span class="pre">Actor</span></code> class (on the Python side) has a corresponding
<code class="docutils literal notranslate"><span class="pre">PytchActor</span></code> object on the JavaScript side. This is responsible for
holding the Costumes of a <code class="docutils literal notranslate"><span class="pre">Sprite</span></code> (or Backdrops of a <code class="docutils literal notranslate"><span class="pre">Stage</span></code>), its
Sounds, and the list of live instances of that <code class="docutils literal notranslate"><span class="pre">Actor</span></code>. There is
exactly one live instance for the <code class="docutils literal notranslate"><span class="pre">Stage</span></code>; there is at least one for a
<code class="docutils literal notranslate"><span class="pre">Sprite</span></code>, but there can be more (if clones have been created).</p>
<p>We store a reference to the Python class object inside the JavaScript
<code class="docutils literal notranslate"><span class="pre">PytchActor</span></code>. For ease of going the other way for some syscalls (DOC
TODO: which?), we also attach a property to the Python class object
referring back to the JavaScript <code class="docutils literal notranslate"><span class="pre">PytchActor</span></code>.</p>
<p>On construction of the <code class="docutils literal notranslate"><span class="pre">PytchActor</span></code>, we create one Python instance,
and a corresponding <code class="docutils literal notranslate"><span class="pre">PytchActorInstance</span></code> object on the JavaScript
side. This Python object is the ‘original’ instance, also sometimes
referred to as ‘instance-0’.</p>
<section id="loading-costumes-backdrops-and-sounds">
<h2>Loading costumes / backdrops and sounds<a class="headerlink" href="#loading-costumes-backdrops-and-sounds" title="Link to this heading">¶</a></h2>
<p>In web-app, this loading will be asynchronous, so the general logic has
to be too. Skulpt has a mechanism for using JavaScript promises as
Skulpt suspensions (and mapping the other way too) so this interface
point is fairly straightforward.</p>
</section>
<section id="pytchactorinstance">
<h2><code class="docutils literal notranslate"><span class="pre">PytchActorInstance</span></code><a class="headerlink" href="#pytchactorinstance" title="Link to this heading">¶</a></h2>
<p>An object of the JavaScript class <code class="docutils literal notranslate"><span class="pre">PytchActorInstance</span></code> corresponds to
a registered Python instance of an <code class="docutils literal notranslate"><span class="pre">Actor</span></code>-derived class. It knows
which <code class="docutils literal notranslate"><span class="pre">PytchActor</span></code> it’s an instance of, and it knows the Python-side
object it represents.</p>
<p>The consequences of a Python object being a ‘registered’ instance of an
<code class="docutils literal notranslate"><span class="pre">Actor</span></code> class are as follows. Within the web-app, Pytch will render it
on the screen. The object will have methods called on it in response to
events such as keypresses or broadcasts.</p>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper"><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../webapp/user/index.html">Using the Pytch web app</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user/index.html">Writing Pytch programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../about.html">About Pytch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contact.html">Contact</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../developer.html">Developer documentation</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../developer/development-setup.html">Development setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../developer/design-overview.html">Design overview</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">VM</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="overview.html">Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="integration-with-client.html">Integration with client</a></li>
<li class="toctree-l3"><a class="reference internal" href="based-on-skulpt.html">Skulpt: Python / JavaScript bridge</a></li>
<li class="toctree-l3"><a class="reference internal" href="project.html">Project</a></li>
<li class="toctree-l3"><a class="reference internal" href="actor.html">Actor: Sprite and Stage</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Actor-class registration</a></li>
<li class="toctree-l3"><a class="reference internal" href="threading-model.html">Threading model</a></li>
<li class="toctree-l3"><a class="reference internal" href="hat-blocks.html">Hat blocks</a></li>
<li class="toctree-l3"><a class="reference internal" href="syscalls.html">Syscalls</a></li>
<li class="toctree-l3"><a class="reference internal" href="skulpt-pytch-environment.html">Skulpt API / Pytch environment</a></li>
<li class="toctree-l3"><a class="reference internal" href="testing.html">Testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="ide-web-app.html">Web-app</a></li>
<li class="toctree-l3"><a class="reference internal" href="rendering.html">Rendering</a></li>
<li class="toctree-l3"><a class="reference internal" href="hit-detection.html">Collision and click detection</a></li>
<li class="toctree-l3"><a class="reference internal" href="clones.html">Clones</a></li>
<li class="toctree-l3"><a class="reference internal" href="sounds.html">Sounds</a></li>
<li class="toctree-l3"><a class="reference internal" href="tutorials.html">Tutorials</a></li>
<li class="toctree-l3"><a class="reference internal" href="docstrings.html">Docstrings</a></li>
<li class="toctree-l3"><a class="reference internal" href="attribute-watchers.html">Watching object attributes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../webapp/developer/index.html">Webapp</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../medialib/developer/index.html">Media library</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../developer/index.html">Website</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../build-tools/index.html">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../source-build.html">Source and build information</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../releases/changelog.html">Changelog</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../legal/index.html">Legal information</a></li>
</ul>
<div class="docs-home-link"><hr>
  <ul>
    <li>
      <a href="../../index.html">Pytch help home</a>
    <li>
  </ul>
</div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
  </body>
</html>